package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SensorType;
import com.ruoyi.system.service.ISensorTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 传感器分类Controller
 * 
 * @author ruoyi
 * @date 2020-09-10
 */
@RestController
@RequestMapping("/sensor/sensortype")
public class SensorTypeController extends BaseController
{
    @Autowired
    private ISensorTypeService sensorTypeService;

    /**
     * 查询传感器分类列表
     */
    @PreAuthorize("@ss.hasPermi('sensor:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(SensorType sensorType)
    {
        startPage();
        List<SensorType> list = sensorTypeService.selectSensorTypeList(sensorType);
        return getDataTable(list);
    }

    /**
     * 导出传感器分类列表
     */
    @PreAuthorize("@ss.hasPermi('sensor:type:export')")
    @Log(title = "传感器分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SensorType sensorType)
    {
        List<SensorType> list = sensorTypeService.selectSensorTypeList(sensorType);
        ExcelUtil<SensorType> util = new ExcelUtil<SensorType>(SensorType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 获取传感器分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('sensor:type:query')")
    @GetMapping(value = "/{sensorTypeId}")
    public AjaxResult getInfo(@PathVariable("sensorTypeId") Long sensorTypeId)
    {
        return AjaxResult.success(sensorTypeService.selectSensorTypeById(sensorTypeId));
    }

    /**
     * 新增传感器分类
     */
    @PreAuthorize("@ss.hasPermi('sensor:type:add')")
    @Log(title = "传感器分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SensorType sensorType)
    {
        return toAjax(sensorTypeService.insertSensorType(sensorType));
    }

    /**
     * 修改传感器分类
     */
    @PreAuthorize("@ss.hasPermi('sensor:type:edit')")
    @Log(title = "传感器分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SensorType sensorType)
    {
        return toAjax(sensorTypeService.updateSensorType(sensorType));
    }

    /**
     * 删除传感器分类
     */
    @PreAuthorize("@ss.hasPermi('sensor:type:remove')")
    @Log(title = "传感器分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sensorTypeIds}")
    public AjaxResult remove(@PathVariable Long[] sensorTypeIds)
    {
        return toAjax(sensorTypeService.deleteSensorTypeByIds(sensorTypeIds));
    }
}
